package com.coocaa.app.gamecenter.pages.arsenal;

import android.content.Context;
import android.view.View;

import com.coocaa.app.gamecenter.pages.arsenal.data.WeaponData;
import com.coocaa.app.gamecenter.pages.arsenal.data.WeaponItemData;
import com.coocaa.app.gamecenter.pages.arsenal.view.ArsenalItemView;
import com.coocaa.app.gamecenter.pages.arsenal.view.ItemView;
import com.coocaa.framework.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xfk on 2015/11/5.
 */
public class ItemViewAdapter extends BaseAdapter<WeaponItemData> {
    private Context mContext = null;
    private List<WeaponItemData> weaponDataList = new ArrayList<WeaponItemData>();

    public ItemViewAdapter(Context context) {
        mContext = context;
    }
    @Override
    public int getCount() {
        return weaponDataList.size();
    }

    @Override
    public int getPosition() {
        return 0;
    }

    @Override
    public void refreshUI(List<WeaponItemData> datas) {
        if(datas != null && datas.size() > 0) {
            weaponDataList.addAll(datas);
            notifyDataSetChanaged();
        }
    }

    @Override
    public View getView(int position, View convertView, boolean[] turnpage) {
        View view;
        if(convertView != null) {
            view = convertView;
        } else {
            view = new ItemView(mContext);
            ((ItemView)view).setData(weaponDataList.get(position));
        }

        view.setId(position);
        return view;
    }

    @Override
    public void destory() {
        if(weaponDataList != null) {
            weaponDataList.clear();
            weaponDataList = null;
        }
    }
}
